<?php

namespace App\Plugin\HostServer\Admin;

use App\Plugin\HostServer\Models\PnHostSvCard;
use Carbon\Carbon;
use Illuminate\Http\Request;

class CardController extends BaseController
{
    public $pageName = '卡密管理';

    public function setModel()
    {
        $this->model = new PnHostSvCard();
    }


    public function indexData()
    {
        $item = [];
        $status=key_value_arr_to_select(PnHostSvCard::getStatus());
        array_unshift($status,['id'=>'','name'=>'全部']);
        $item['all_create_url'] = action($this->route['controller_name'] . '@allCreate', \request()->all());
        $item['all_post_url'] = action($this->route['controller_name'] . '@allCreatePost');
        $item['status']=$status;
        return $item;
    }

    public function apiJsonItemExtend($item)
    {
        $item->user_name = $item->user['name'];
        $item->type_name = $item->status_name;
        return $item;
    }

    /**
     * 批量验证规则
     * @return array
     */
    public function allCreateCheckForm()
    {
        $error = $this->checkForm($this->rq->all(), $this->checkRule(''), $this->checkRuleMsg(), $this->checkRuleField());
        return $error;
    }

    public function checkRule($id = '')
    {

        return [
            'number' => 'required',
            'money' => 'required',
            'invalid_at' => 'required'

        ];

    }

    public function checkRuleMsg()
    {
        return [
            'number' => '数量',
            'money' => '面额',
            'invalid_at' => '过期时间'

        ];
    }

    /**
     * 批量添加设置数据
     * @param Request $request
     * @return array|void
     */
    public function allCreateSetData(Request $request)
    {
        $number = $request->input('number');
        $money = $request->input('money');
        $invalid_at = $request->input('invalid_at');

        $arr = [];



         $arr = pn_host_server_make_card($number, $money,$invalid_at);



        return $arr;
    }


}
